﻿@inherits BaseComponent

<TypeForm Class="kui-system" Model="Model" Style="margin-top:20px">
    <AntRow>
        <DataItem Label="@Language[nameof(SystemInfo.CompName)]">
            @($"{Model.System.CompNo}-{Model.System.CompName}")
        </DataItem>
    </AntRow>
    <AntRow>
        <DataItem Label="@Language[nameof(SystemInfo.AppName)]">
            <KEditInput Value="@Model.System.AppName" OnSave="OnSaveAppNameAsync" />
        </DataItem>
    </AntRow>
    <AntRow>
        <DataItem Label="@Language[nameof(VersionInfo.AppVersion)]">@Model.Version.AppVersion</DataItem>
    </AntRow>
    <AntRow>
        <DataItem Label="@Language[nameof(VersionInfo.SoftVersion)]">@Model.Version.SoftVersion</DataItem>
    </AntRow>
    <AntRow>
        <DataItem Label="@Language[nameof(VersionInfo.BuildTime)]">
            @($"{Model.Version.BuildTime:yyyy-MM-dd HH:mm:ss}")
        </DataItem>
    </AntRow>
    <AntRow>
        <DataItem Label="@Language[nameof(VersionInfo.FrameVersion)]">@Model.Version.FrameVersion</DataItem>
    </AntRow>
    <AntRow>
        <DataItem Label="@Language[nameof(SystemDataInfo.RunTime)]">@($"{Model.RunTime} H")</DataItem>
    </AntRow>
    @if (!Config.App.IsPlatform && !string.IsNullOrWhiteSpace(Model.System.ProductId))
    {
        <AntRow>
            <DataItem Label="@Language[nameof(SystemInfo.ProductId)]">@Model.System.ProductId</DataItem>
            <DataItem Label="@Language[nameof(SystemInfo.ProductKey)]">
                <KEditInput Value="@Model.System.ProductKey" OnSave="OnSaveProductKeyAsync" />
            </DataItem>
        </AntRow>
    }
    @if (!string.IsNullOrWhiteSpace(AdminOption.Instance.Copyright))
    {
        <AntRow>
            <DataItem Label="@Language[nameof(VersionInfo.FrameVersion)]">@AdminOption.Instance.Copyright</DataItem>
        </AntRow>
    }
    @if (!string.IsNullOrWhiteSpace(AdminOption.Instance.SoftTerms))
    {
        <AntRow>
            <DataItem Label="@Language[nameof(VersionInfo.FrameVersion)]">@AdminOption.Instance.SoftTerms</DataItem>
        </AntRow>
    }
</TypeForm>

@code {
    private SystemDataInfo Model;
    [CascadingParameter] private SysSystem Parent { get; set; }

    protected override async Task OnInitAsync()
    {
        await base.OnInitAsync();
        Model = Parent.Model;
    }

    private async Task OnSaveAppNameAsync(string value)
    {
        Model.System.AppName = value;
        var result = await Parent.SaveSystemAsync(Model.System);
        if (result.IsValid)
        {
            CurrentUser.AppName = value;
            await App?.StateChangedAsync();
        }
    }

    private async Task OnSaveProductKeyAsync(string value)
    {
        Model.System.ProductKey = value;
        await Parent.SaveKeyAsync(Model.System);
        await StateChangedAsync();
    }
}